<template>
<div>
  <el-button @click="deploy">流程部署</el-button>
  <el-button @click="toAdd">添加</el-button>
  <el-button @click="download">导出Pdf</el-button>
  <el-form :inline="true" :model="apply" class="demo-form-inline">
    <el-form-item label="合同名称">
      <el-input v-model="apply.title" placeholder="合同名称"></el-input>
    </el-form-item>
    <el-form-item label="合同内容">
      <el-input  v-model="apply.reason" placeholder="合同内容"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="initTable">查询</el-button>
    </el-form-item>
  </el-form>
  <template>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="title" label="合同名称"></el-table-column>
      <el-table-column prop="reason" label="合同内容"></el-table-column>
      <el-table-column prop="money" label="合同金额"></el-table-column>
<!--      <el-table-column prop="remark" label="备注"></el-table-column>-->
      <el-table-column prop="created" label="创建时间"></el-table-column>
      <el-table-column  label="提交审核">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleEdit(scope.row)">提交审核</el-button>
<!--          <el-button
              size="mini"
              @click="flow(scope.row)">流程状态</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[3, 5, 10]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </template>
</div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      tableData: [],
      page:1,
      size:3,
      total:0,
      apply:{}
    }
  },
  created() {
    this.initTable()
  },
  methods:{
    download() {
      window.open("http://localhost:81/apply/export")
    },
    toLogin() {
      this.$router.push("/login")
    },
    toTask() {
      this.$router.push("/task")
    },
    toAdd() {
      this.$router.push("/add")
    },
    deploy() {
      this.axios.get("http://localhost:81/apply/deploy").then(
          res=>{
            if (res.data.code === 200) {
              this.$message.success("部署成功")
            }
          }
      )
    },
    handleEdit(row) {
      this.axios.get("http://localhost:81/apply/biz?id="+row.id).then(
        res=>{
          if (res.data.code === 200) {
            this.$message.success("申请审核成功")
          }
        }
      )
    },
    flow(row) {
      window.open("http://localhost:81/apply/getFlowImgByInstanceId?processInstanceId="+row.taskid,'_blank')
    },
    initTable() {
      this.axios.get("http://localhost:81/apply/list",{
        params:{page:this.page,size:this.size,
          title:this.apply.title,reason:this.apply.reason,remark:this.apply.remark}
      }).then(
          res=>{
            this.tableData = res.data.records
            this.total =res.data.total
          }
      )
    },
    handleSizeChange(val) {
      this.size =val
      this.initTable()
    },
    handleCurrentChange(val) {
      this.page =val
      this.initTable()
    }
  }
}
</script>

<style scoped>

</style>
